import 'package:flutter_syt/datas/number_extension.dart';

class ArticleListItem {
  late String id;
  late String title;
  late String description;
  late String thumb;
  late int width;
  late int height;
  late String video;
  late String duration;
  late String author;
  late int publish_time;
  late String content;
  late String article_type;
  late String cover;
  late String linkUrl;
  late String tag;
  late String showBig;

  ArticleListItem(Map<String, dynamic> json) {
    this.id = "${json["id"]}";
    this.title = "${json["title"]}";
    this.description = "${json["description"]}";
    this.thumb = "${json["thumb"]}";
    try {
      this.width = parseInt(json["width"]);
    } catch (e) {
      this.width = 1;
    }
    try {
      this.height = parseInt(json["height"]);
    } catch (e) {
      this.height = 1;
    }

    this.video = '${json["video"]}';
    this.duration = '${json["duration"]}';
    this.author = "${json["author"]}";
    try {
      this.publish_time = int.parse("${json["publish_time"]}");
    } catch (e) {
      this.publish_time = 0;
    }
    this.content = json["content"] as String? ?? "";
    this.article_type = "${json["article_type"]}";
    this.cover = "${json["cover"]}";
    this.linkUrl = "${json["path"]}";
    List? tags = (json["tags"] == null || json["tags"].length == 0)
        ? <String>[]
        : (json["tags"] as List).map((e) => '$e').toList();
    this.tag = "";
    if (tags.length > 0) {
      this.tag = "${tags[0]}";
    }
    this.showBig = "${json["show_big"]}";
  }

  Map<String, dynamic> get json {
    var result = Map<String, dynamic>();
    result["id"] = this.id;
    result["title"] = this.title;
    result["description"] = this.description;
    result["thumb"] = this.thumb;
    result["width"] = this.width;
    result["height"] = this.height;
    result["video"] = this.video;
    result["duration"] = this.duration;
    result["author"] = this.author;
    result["publish_time"] = this.publish_time;
    result["content"] = this.content;
    result["article_type"] = this.article_type;
    result["cover"] = this.cover;
    result["linkUrl"] = this.linkUrl;
    result["show_big"] = this.showBig;
    return result;
  }
}

class ArticleTypes {
  late String id;
  late String name;
  late String type;
  late String showType; //show_type：1纯列表展示，2:一行两个，3:一行三个
  late String target;
  late String path;
  late String column_id;
  late String title;
  late String alias;

  ArticleTypes(Map<String, dynamic> json) {
    this.id = "${json["id"]}";
    this.name = "${json["name"]}";
    this.type = "${json["type"]}";
    this.title = "${json["title"]}";
    this.showType = "${json["show_type"]}";
    this.target = "${json["target"]}";
    this.path = "${json["path"]}";
    this.column_id = "${json["column_id"]}";
    this.alias = "${json["alias"]}";
  }

  Map<String, dynamic> get json {
    var result = Map<String, dynamic>()
      ..["id"] = this.id
      ..["name"] = this.name
      ..["type"] = this.type
      ..["show_type"] = this.showType
      ..["target"] = this.target
      ..["path"] = this.path
      ..["column_id"] = this.column_id
      ..["alias"] = this.alias;
    return result;
  }
}
